package db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import model.type.AddressType;


public class AddressTypeDAO {
	private static final String TABLE = "address_type";	
	private static String onSqlError = "SQL statement fault";
		
	@SuppressWarnings("unused")
	private static final String 
		ID_FIELD = "address_type",			
		TYPE_NAME_FIELD = "type_name";
	
	public static ArrayList<AddressType> getAll() {			
		try{				
			Statement st = ImbiConnection.getConnection().createStatement();
			st.executeQuery("SELECT * FROM "+TABLE);
			ResultSet r = st.getResultSet();			
			ArrayList<AddressType> addressTypes = new ArrayList<AddressType>();
						
			while(r.next()){				
				addressTypes.add(
					new AddressType(
						r.getInt(1), 						
						r.getString(2)					
					)
				);
			}
			return addressTypes;
		} catch (SQLException s){
				System.out.println(onSqlError);				
				return null;
		}		
	}	
}
